namespace TomatoBreak.UnitSpecs.Routing
{
    using System.Web.Routing;

    using Machine.Specifications;

    using Infrastructure;

    public abstract class RoutingSpec
    {
        protected static RouteExecuter app;
        protected static RouteMatchingResult result;

        Establish context = () =>
        {
            var routes = new RouteCollection();
            new RoutesRegistrar(routes).Register();

            app = new RouteExecuter(routes);
        };
    }

    [Subject(typeof(RoutesRegistrar))]
    public class when_getting_application_root : RoutingSpec
    {
        Because of = () => result = app.Get("~/");

        It should_match_home_index = () =>
        {
            result.Controller.ShouldEqual("home");
            result.Action.ShouldEqual("index");
        };
    }

    [Subject(typeof(RoutesRegistrar))]
    public class when_posting_user : RoutingSpec
    {
        Because of = () => result = app.Post("~/user");

        It should_match_user_create = () =>
        {
            result.Controller.ShouldEqual("user");
            result.Action.ShouldEqual("create");
        };
    }

    [Subject(typeof(RoutesRegistrar))]
    public class when_posting_session : RoutingSpec
    {
        Because of = () => result = app.Post("~/session");

        It should_match_session_create = () =>
        {
            result.Controller.ShouldEqual("session");
            result.Action.ShouldEqual("create");
        };
    }

    [Subject(typeof(RoutesRegistrar))]
    public class when_deleting_session : RoutingSpec
    {
        Because of = () => result = app.Delete("~/session");

        It should_match_session_destroy = () =>
        {
            result.Controller.ShouldEqual("session");
            result.Action.ShouldEqual("destroy");
        };
    }

    [Subject(typeof(RoutesRegistrar))]
    public class when_getting_dashboard : RoutingSpec
    {
        Because of = () => result = app.Get("~/dashboard");

        It should_match_dashboard_index = () =>
        {
            result.Controller.ShouldEqual("dashboard");
            result.Action.ShouldEqual("index");
        };
    }
}